<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="path" value="${pageContext.request.contextPath }" />
<%@taglib prefix="priv" uri="/mytag/privilege"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户维护页面</title>
<script type="text/javascript" src="${path}/js/scripts/bootstart.js"></script>
</head>
<body style="width: 98%; height: 90%;">
	<div style="width: 100%;">
		<div id="searchForm" class="mini-toolbar"
			style="border-bottom: 0; padding: 0px;">
			<table width="100%" border="0">
				<tr>
					<td style="width: 100%;"><priv:priv-btn btnname="search">用户姓名: <input
								class="mini-textbox" name="userName" emptyText="请输入用户姓名，支持模糊查询"
								style="width: 210px;" />
						用户账号: <input class="mini-textbox" name="jobNo"
								emptyText="请输入用户账号，支持模糊查询" style="width: 210px;" /> 电话号码: <input
								class="mini-textbox" name="telephone" emptyText="请输入电话号码，支持模糊查询"
								style="width: 210px;" />
							<a class="mini-button" onclick="datagrid.Search()"
								iconCls="icon-search">查询</a>
							<a class="mini-button" iconCls="icon-undo"
								onclick="datagrid.Clear()">重置</a>
						&nbsp;&nbsp;&nbsp;</priv:priv-btn> <priv:priv-btn btnname="add">
							<a class="mini-button" iconCls="icon-add"
								onclick="datagrid.showAdd">增加</a>&nbsp;
						</priv:priv-btn> <priv:priv-btn btnname="edit">
							<a class="mini-button" iconCls="icon-edit"
								onclick="datagrid.edit()">修改</a>&nbsp;
						</priv:priv-btn> <priv:priv-btn btnname="lock">
							<a class="mini-button" iconCls="icon-lock"
								onclick="datagrid.locked()">锁定</a>&nbsp;
						</priv:priv-btn> <priv:priv-btn btnname="unlock">
							<a class="mini-button" iconCls="icon-unlock"
								onclick="datagrid.unlocked()">解锁</a>&nbsp;
						</priv:priv-btn> <priv:priv-btn btnname="resetpassword">
							<a class="mini-button" iconCls="icon-reload"
								onclick="datagrid.resetpassword()">重置密码</a>&nbsp;
						</priv:priv-btn> <priv:priv-btn btnname="remove">
							<a class="mini-button" iconCls="icon-remove"
								onclick="datagrid.remove()">删除</a>&nbsp;
						</priv:priv-btn></td>
				</tr>
			</table>
		</div>
	</div>
	<div id="datagrid1" class="mini-datagrid"
		url="${path}/user/mgr/showList" pageSize="10"
		style="width: 100%; height: 90%;" allowResize="false" idField="userId"
		multiSelect="true" dataField="list" totalField="totalRecord"
		sizeList="[10,20,30]" sortField="userId" sortOrder="desc">
		<div property="columns">
			<div type="checkcolumn"></div>
			<div field="userName" width="80" headerAlign="center"
				allowSort="true">用户姓名</div>
			<div field="roleName" headerAlign="center" width="100"
				allowSort="true">角色</div>
			<div field="isLocked" headerAlign="center" width="70"
				renderer="datagrid.lockedRenderer" allowSort="true">是否活动</div>
			<div field="jobNo" headerAlign="center" width="100" allowSort="true">用户账号</div>
			<div field="telephone" headerAlign="center" width="100"
				allowSort="true">电话号码</div>
			<div field="email" headerAlign="center" width="100" allowSort="true">邮箱</div>
			<div field="birthday" headerAlign="center" width="70"
				dateFormat="yyyy-MM-dd" allowSort="true">生日</div>
			<div field="addTime" headerAlign="center" width="100"
				dateFormat="yyyy-MM-dd HH:mm:ss" allowSort="true">添加时间</div>
			<div field="remark" headerAlign="center" width="100">备注</div>
		</div>
	</div>
	<span style="color: red;">${errorMsg}</span>
	<script type="text/javascript" src="${path}/js/scripts/datagrid.js"></script>
	<script type="text/javascript" src="${path}/js/scripts/utils.js"></script>
	<script type="text/javascript" src="${path}/js/message.js"></script>
	<script type="text/javascript">
		mini.parse();
		var doc = $(document);
		$(function() {
			$.grid.init({
				id : "datagrid1"
			});
			window.datagrid = {};
			datagrid.showAdd = function() {
				$.grid.add({
					url : "${path}/user/mgr/userform",
					title : "用户添加",
					width : doc.width() * 0.7 + "px",
					height : doc.height() * 0.7 + "px"
				});
			};
			datagrid.edit = function() {
				var rows = $.grid.datagrid.getSelecteds();
				if (rows.length > 1) {
					mini.alert("只能修改一个用户！");
					return;
				}
				$.grid.edit({
					url : "${path}/user/mgr/userform?flag=edit",
					title : "用户修改",
					formId : "userForm",
					fieldId : "userId",
					width : doc.width() * 0.7 + "px",
					height : doc.height() * 0.7 + "px",
					dataUrl : "${path}/user/mgr/showUpdate"
				});
			};
			datagrid.lockedRenderer = function(e) {
				if (e.value == "0") {
					return "活动";
				}
				return "锁定";
			};

			datagrid.remove = function() {
				$.grid.remove({
					url : "${path}/user/mgr/deleteUser",
					paramName : "key", //获取参数的参数名
					showMsg : true,//是否显示提示信息（删除成功与否返回信息）
					fldId : "userId" //获取选中列的主键值对应的列名 
				});
			};

			datagrid.resetpassword = function() {
				var rows = $.grid.datagrid.getSelecteds();
				if (rows.length > 1) {
					mini.alert("只能操作一条数据！");
					return;
				}
				var row = $.grid.datagrid.getSelected();
				if (!row) {
					mini.alert("请选择要重置密码的用户!");
					return;
				}
				if (row.isLocked == "1") {
					mini.alert("用户【" + row.userName + "】已锁定!");
					return;
				}
				mini.confirm("确定要重置该用户密码吗？重置后密码为:123456", "友情提示", function(e) {
					if (e == 'ok') {
						$.ajax({
							url : "${path}/user/mgr/resetPassword",
							cache : false,
							post : "post",
							data : "userId=" + row.userId,
							success : function(obj) {
								tips.show(obj, '', 5000, '#DFF0D8', 150);
							}
						});
					}
				});
			};
			datagrid.locked = function() {
				var rows = $.grid.datagrid.getSelecteds();
				if (rows.length > 1) {
					mini.alert("只能操作一条数据！");
					return;
				}
				var row = $.grid.datagrid.getSelected();
				if (!row) {
					mini.alert("请选择要锁定的用户!");
					return;
				}

				if (row.isLocked == "1") {
					mini.alert("用户【" + row.userName + "】已锁定!");
					return;
				}

				doLockState(1, "锁定", row.userId);
			};

			datagrid.unlocked = function() {
				var rows = $.grid.datagrid.getSelecteds();
				if (rows.length > 1) {
					mini.alert("只能操作一条数据！");
					return;
				}
				var row = $.grid.datagrid.getSelected();
				if (!row) {
					mini.alert("请选择要解锁的用户!");
					return;
				}
				if (row.isLocked == "0") {
					mini.alert("用户【" + row.userName + "】已解锁!");
					return;
				}

				doLockState(0, "解锁", row.userId);
			};

			var doLockState = function(state, msg, id) {
				mini.confirm("您确定" + msg + "选中的记录?", "温馨提示", function(e) {
					if (e == "ok") {
						$.ajax({
							url : "${path}/user/mgr/updateUserLock?locked="
									+ state + "&userId=" + id,
							success : function(obj) {
								if (obj == "true") {
									$.grid.datagrid.reload();
									tips.show(msg + "用户成功", '', 5000,
											'#DFF0D8', 150);
								} else {
									tips.show(msg + "用户失败", '', 5000,
											'#DFF0D8', 150);
								}
							}
						});
					}
				});
			};
			//清除查询条件
			datagrid.Clear = function() {
				var SerachForm = new mini.Form("searchForm");
				SerachForm.reset();
			};
			//查询
			datagrid.Search = function() {
				var SerachForm = new mini.Form("searchForm");
				var data = SerachForm.getData(true);
				//获取以Struts2对象封装格式的json对象 {"对象1.属性":"属性值","对象.属性2":"属性值"}
				var jsonObject = myutils.parseFormToJsonObject(data);
				$.grid.datagrid.load(jsonObject);
			};
		});
	</script>
</body>
</html>